/*
 * Tencent is pleased to support the open source community by making QMUI_Android available.
 *
 * Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved.
 *
 * Licensed under the MIT License (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 *
 * http://opensource.org/licenses/MIT
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.qmuiteam.qmuidemo.manager;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import com.bitbank.smartdevice.manager.QDUpgradeManager



/**
 * Created by cgspine on 2018/1/14.
 */

class QDPreferenceManager private constructor(context: Context) {

    val versionCode: Int
        get() = sPreferences.getInt(APP_VERSION_CODE, QDUpgradeManager.INVALIDATE_VERSION_CODE)

    init {
        sPreferences = PreferenceManager.getDefaultSharedPreferences(context.applicationContext)
    }

    fun setAppVersionCode(code: Int) {
        val editor = sPreferences.edit()
        editor.putInt(APP_VERSION_CODE, code)
        editor.apply()
    }

    companion object {
        private lateinit var sPreferences: SharedPreferences
        private var sQDPreferenceManager: QDPreferenceManager? = null

        private val APP_VERSION_CODE = "app_version_code"

        fun getInstance(context: Context): QDPreferenceManager {
            if (sQDPreferenceManager == null) {
                sQDPreferenceManager = QDPreferenceManager(context)
            }
            return sQDPreferenceManager as QDPreferenceManager
        }
    }
}
